#include "src/base/fio66_logger.h"

#include "src/base/utils.h"

namespace fio66
{

Fio66Logger* Fio66Logger::GetInstance() {
  static Fio66Logger rtsp_logger;
  return &rtsp_logger;
}

bool Fio66Logger::Init(std::string_view client_name) {
  auto log_dir = utils::GetExeDir();
  log_dir += "log";
  printf("log-dir:%s\n", log_dir.c_str());
  if (!log_dir.empty()) {
    FLAGS_log_dir = log_dir;
  }

  FLAGS_minloglevel = 0;  // 0 info 1 warning 2 error 3 fatal
  FLAGS_max_log_size = 500;
  FLAGS_alsologtostderr = true;
  FLAGS_stop_logging_if_full_disk = true;
  google::InitGoogleLogging(client_name.data());
  return true;
}

void Fio66Logger::Uninit() {
  google::ShutdownGoogleLogging();
}

__thread char t_errnobuf[512];
__thread char t_time[64];
__thread time_t t_lastSecond;

const char* strerror_tl(int savedErrno)
{
  return strerror_r(savedErrno, t_errnobuf, sizeof t_errnobuf);
}

} // namespace fio66
